<!-- 维修已办 -->
<template>
	<view>
		<view class="no-warpper" v-if="isLong">
			<!-- 有数据 渲染列表 -->
			<view v-if="hasInfo">
				<view class="scroll-box">
					<view class="nl-shadow-box card-box" v-for="(item,index) in repairList" :key="index">
						<view class="nl-flex-list title">
							<view>{{item.repairId}}</view>
							<text :class="item.state == '1100' ? 'blue' : (item.state == '1200' ? 'yellow':'red')">{{item.stateName}}</text>
						</view>
						<view class="nl-flex-list">
							<view class="content" @click="repairDetail(item)">
								
								<view class="item">
									<view>报修类型</view>
									<text>：</text>
									<view>{{item.repairTypeName}}</view>
								</view>
								<view class="item">
									<view>报修人</view>
									<text>：</text>
									<view>{{item.repairName}}</view>
								</view>
								<view class="item">
									<view>联系方式</view>
									<text>：</text>
									<view>{{item.tel}}</view>
								</view>
								<view class="item">
									<view>报修位置</view>
									<text>：</text>
									<view>{{item.repairObjName}}</view>
								</view>
								<view class="item">
									<view>预约时间</view>
									<text>：</text>
									<view>{{item.appointmentTime}}</view>
								</view>
								<view class="item">
									<view>报修内容</view>
									<text>：</text>
									<view>{{item.context}}</view>
								</view>
							</view>
						</view>
						<view class="botton-flex">
							<view class="button-mini line m8" @click="repairDetail(item)">
								<button>详情</button>
							</view>
						</view>
					</view>
					
					<u-loadmore :status="status" />
				</view>
			</view>
			<!-- 无数据 渲染缺省图 -->
			<view v-if="hasInfo == false">
				<noData :noDataText="noDataText"></noData>
			</view>
		</view>
		<view v-else>
			<netError v-if="!hasNet" @refresh="refresh()"></netError>
		</view>
	</view>

</template>

<script>
	import {
		getFinishRepairs
	} from 'api/repair';
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				listBox: [], // 避免上拉刷新时，页面出现空白
				repairList: [],
				page: 1,
				records: 0,
				status: 'loadmore',

				isLong: false, // 是否加载完成
				hasNet: true, // 是否有网络
				hasInfo: '', // 是否有数据
				noDataText: '暂无数据~',
			}
		},
		computed: {
			...mapState('user', ['userInfo', 'userCommunity'])
		},
		onLoad() {
			this.getFinishRepairs(this.page)
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.records = 0
			this.listBox = []
			this.getFinishRepairs(1)
		},
		onReachBottom() {
			console.log('页面触底了')
			if (this.status == 'loading') { // 防止多次触发

			} else {
				this.status = 'loading';
				if (this.page <= this.records) {
					this.getFinishRepairs(this.page)
				} else {
					this.status = 'nomore';
				}
			}
		},
		methods: {
			/**
			 * 获取维修已办列表
			 */
			getFinishRepairs(page) {
				var that = this
				const data = {
					userId: this.userInfo.userId,
					communityId: this.userCommunity.communityId,
					page: page,
					row: 10
				}
				getFinishRepairs(data).then((res) => {
					console.log('获取维修已办', res)
					if (res.code == 0) {
						if (res.data.length == 0) { //暂无数据
							that.hasInfo = false
							that.isLong = true;
							uni.hideLoading()
							uni.stopPullDownRefresh()
							return;
						}

						that.records = res.records
						if (that.records == that.page) {
							that.status = 'nomore';
						}
						that.page++
						uni.stopPullDownRefresh()
						for (let i of res.data) {
							that.listBox.push(i)
						}

						that.repairList = that.listBox
					}
					that.isLong = true
					that.hasInfo = true
				}).catch(function(reason) {
					uni.stopPullDownRefresh()
					// 处理网络错误
					that.hasNet = false
					that.isLong = false
				})
			},
			/**
			 * 刷新
			 */
			refresh() {
				this.repairList = []
				this.page = 1
				this.records = 0
				this.getFinishRepairs(1)
			},
			/**
			 * 跳转工单详情
			 */
			repairDetail(item) {
				uni.navigateTo({
					url: "/pages/home/repairWaiting/repairDetails/repairDetails?repairId=" +
						item.repairId
				});
			},

		}
	}
</script>

<style lang="scss">
	.repair-content {
		width: 100%;
		background-color: #F3F9FF;
		padding: 24rpx;

		.repair-item {
			display: flex;
			align-items: center;
			justify-content: flex-start;
			font-size: $uni-font-size-base;
			margin-bottom: 12rpx;

			view:nth-child(1) {
				width: 140rpx;
				text-align-last: justify;
				color: $nl-text-color-grey;
			}

			text {
				color: $nl-text-color-grey;
			}

			view:nth-of-type(2) {
				flex: 1;
			}
		}

		.repair-item:last-child {
			align-items: flex-start;
			margin-bottom: none
		}
	}

	.scroll-box {
		width: 100%;
		// height: calc(100vh - 48rpx);
		padding-bottom: 32rpx;
	}
</style>
